package com.hzdesk.media.koreabatchmatvector.request;

import android.content.Context;
import android.util.Log;


import com.hzdesk.media.koreabatchmatvector.bean.MeetingConfig;
import com.hzdesk.media.koreabatchmatvector.inter.ICallBack;
import com.hzdesk.media.koreabatchmatvector.utils.JsonUitl;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

import static android.webkit.WebSettings.PluginState.ON;

/**
 * Created by Administrator on 2018/5/25.
 */

public class GetMeetingConfigRequest {
    private static final String TAG=GetMeetingConfigRequest.class.getSimpleName();
    private Model model = Model.getInstance();
    private Context context;
    private String Url;
    public GetMeetingConfigRequest(Context context, String url) {
        this.context = context;
        Url = url;
    }

    public interface OnGetMeetingConfigListener{
        void success(MeetingConfig meetingConfig);
        void fail(String s);
    }
    private OnGetMeetingConfigListener onGetCloudFileListListener;
    private String Success = "SUCCESS";
    private String Fail = "FAIL";

    public void setOnGetMeetingConfigListener(OnGetMeetingConfigListener onGetCloudFileListListener){
        this.onGetCloudFileListListener=onGetCloudFileListListener;
        getRequest(Url);
    }
    public void getRequest(String url) {
        Log.d(TAG,url);
        model.getSynchronized(context, url, new ICallBack() {
            @Override
            public void result(String s) {
               // System.out.println(s);
                try {
                    JSONObject jsonObject=new JSONObject(s);
                    if(jsonObject.has("message")){
                        if (jsonObject.getString("message").equals(Success)){
                            MeetingConfig meetingConfig= (MeetingConfig) JsonUitl.stringToObject(s,MeetingConfig.class);
                            onGetCloudFileListListener.success(meetingConfig);
                        }else if (jsonObject.getString("message").equals(Fail)){
                            onGetCloudFileListListener.fail(s);
                        }
                    }
                } catch (JSONException e) {
                    //e.printStackTrace();
                    Log.d(TAG,s);
                }

            }
        });
    }

}
